<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input id="talk" placeholder="请输入内容与机器人聊天，回车提交" />
    <div id="result"></div>
    <script>
        const talk = document.querySelector("#talk");
        const result = document.querySelector("#result")
        talk.onkeyup = (e) => {
            if (e.key === 'Enter') {
                fetch("http://ajax-api.itheima.net/api/robot?spoken=" + talk.value)
                    .then(res => res.json())
                    .then(res => {
                        result.innerHTML += `<div>机器人：${res.data.info.text}</div>`;
                    })
                result.innerHTML += `<div>我：${talk.value}</div>`;
                talk.value = null;
            }
        }
    </script>
</body>

</html>